/**
 * 
 */
package fr.univ_tln.inf9.exaplanning.api.utilisateur;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.swing.event.EventListenerList;

import fr.univ_tln.inf9.exaplanning.api.composante.TrainingPath;
import fr.univ_tln.inf9.exaplanning.api.db.EntityInfo;
import fr.univ_tln.inf9.exaplanning.api.db.SessionManager;

/**
 * @author pivi
 * @author emilien (Persistance)
 */

@EntityInfo(	collections = { },
				key = "email",
				methods = { "getMail", "getFirst_name", "getName" }, 
				rows = { "email", "first_name", "last_name" },
				table = "student_view",
				variables = { "first_name", "name" })
public class Student extends User {
	
	/**
	 * Constructeur
	 * @throws SQLException 
	 * @throws IOException 
	 * 
	 */
	public Student(String name,String first_name,String mail) throws IOException, SQLException {
		super(true);
		this.name = name;
		this.first_name = first_name;
		this.mail = mail;
		
		listeners = new EventListenerList();
	}
	
	/**
	 * 
	 * @param mail
	 * @param first_name
	 * @param last_name
	 * @param b
	 * @throws IOException
	 * @throws SQLException
	 */
	private Student(String mail, String first_name, String last_name, boolean b) throws IOException, SQLException {
		super(false);
		this.name = last_name;
		this.first_name = first_name;
		this.mail = mail;
	}
	
	public static Student findByKey(String key) throws IOException, SQLException {
    	List<List<String>> data = SessionManager.getInstance().getData(Student.class, key);
    	
    	List<String> variables = data.get(0);
    	Student result = new Student(variables.get(0), variables.get(1), variables.get(2), false);
    	
    	return result;
	}
	
	

}
